﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x0200056A RID: 1386
	public class AnimeGroupList : MonoBehaviour
	{
		// Token: 0x17000449 RID: 1097
		// (get) Token: 0x0600237A RID: 9082 RVA: 0x000D5D94 File Offset: 0x000D3F94
		// (set) Token: 0x0600237B RID: 9083 RVA: 0x000D5DA4 File Offset: 0x000D3FA4
		public bool active
		{
			get
			{
				return base.gameObject.activeSelf;
			}
			set
			{
				if (base.gameObject.activeSelf != value)
				{
					base.gameObject.SetActive(value);
					if (!base.gameObject.activeSelf)
					{
						this.animeCategoryList.active = false;
					}
				}
			}
		}

		// Token: 0x0600237C RID: 9084 RVA: 0x000D5DE0 File Offset: 0x000D3FE0
		public void InitList(AnimeGroupList.SEX _sex)
		{
			if (this.sex == _sex)
			{
				return;
			}
			int childCount = this.transformRoot.childCount;
			for (int i = 0; i < childCount; i++)
			{
				UnityEngine.Object.Destroy(this.transformRoot.GetChild(i).gameObject);
			}
			this.transformRoot.DetachChildren();
			this.scrollRect.verticalNormalizedPosition = 1f;
			this.dicNode = new Dictionary<int, Image>();
			this.sex = _sex;
			foreach (KeyValuePair<int, Info.GroupInfo> keyValuePair in ((this.sex != AnimeGroupList.SEX.Male) ? Singleton<Info>.Instance.dicFAGroupCategory : Singleton<Info>.Instance.dicMAGroupCategory))
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.objectPrefab);
				if (!gameObject.activeSelf)
				{
					gameObject.SetActive(true);
				}
				gameObject.transform.SetParent(this.transformRoot, false);
				GameSceneNode component = gameObject.GetComponent<GameSceneNode>();
				int no = keyValuePair.Key;
				component.AddActionToButton(delegate
				{
					this.OnSelect(no);
				});
				component.text = keyValuePair.Value.name;
				this.dicNode.Add(keyValuePair.Key, gameObject.GetComponent<Image>());
			}
			this.select = -1;
			if (!base.gameObject.activeSelf)
			{
				base.gameObject.SetActive(true);
			}
			this.animeCategoryList.active = false;
			this.animeList.active = false;
		}

		// Token: 0x0600237D RID: 9085 RVA: 0x000D5F98 File Offset: 0x000D4198
		private void OnSelect(int _no)
		{
			int key = this.select;
			if (Utility.SetStruct<int>(ref this.select, _no))
			{
				this.animeCategoryList.InitList(this.sex, _no);
				Image image = null;
				if (this.dicNode.TryGetValue(key, out image) && image != null)
				{
					image.color = Color.white;
				}
				image = null;
				if (this.dicNode.TryGetValue(this.select, out image) && image != null)
				{
					image.color = Color.green;
				}
			}
		}

		// Token: 0x04002461 RID: 9313
		public AnimeGroupList.SEX sex = AnimeGroupList.SEX.Unknown;

		// Token: 0x04002462 RID: 9314
		[SerializeField]
		private Transform transformRoot;

		// Token: 0x04002463 RID: 9315
		[SerializeField]
		private GameObject objectPrefab;

		// Token: 0x04002464 RID: 9316
		[SerializeField]
		private ScrollRect scrollRect;

		// Token: 0x04002465 RID: 9317
		[SerializeField]
		private AnimeCategoryList animeCategoryList;

		// Token: 0x04002466 RID: 9318
		[SerializeField]
		private AnimeList animeList;

		// Token: 0x04002467 RID: 9319
		private int select = -1;

		// Token: 0x04002468 RID: 9320
		private Dictionary<int, Image> dicNode;

		// Token: 0x0200056B RID: 1387
		public enum SEX
		{
			// Token: 0x0400246A RID: 9322
			Male,
			// Token: 0x0400246B RID: 9323
			Female,
			// Token: 0x0400246C RID: 9324
			Unknown
		}
	}
}
